<?php
    
    namespace Home\Controller;
    use Think\Controller;
//    function checkLogin()
//    {
//        if(!isset($_SESSION['id']))
//        {
//             $this->error('请登录管理员账号','__APP__/Admin/Login/login');
////             header('location:./index.php/Admin/Index/login');
//            // success('请登录管理员账号','.//Admin/Login/login');
////            redirect('index1');
//        }
//    }


function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
{
    if(function_exists("mb_substr")){
        if($suffix)
            return mb_substr($str, $start, $length, $charset)."...";
        else
            return mb_substr($str, $start, $length, $charset);
    }
    elseif(function_exists('iconv_substr')) {
        if($suffix)
            return iconv_substr($str,$start,$length,$charset)."...";
        else
            return iconv_substr($str,$start,$length,$charset);
    }
    $re['utf-8']   = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef]
                  [x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
    $re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
    $re['gbk']    = "/[x01-x7f]|[x81-xfe][x40-xfe]/";
    $re['big5']   = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
    preg_match_all($re[$charset], $str, $match);
    $slice = join("",array_slice($match[0], $start, $length));
    if($suffix) return $slice."…";
    return $slice;
}


function cutstr_html($string, $sublen)
{
    $string = strip_tags($string);
    $string = preg_replace ('/\n/is', '', $string);
    $string = preg_replace ('/ |　/is', '', $string);
    $string = preg_replace ('/&nbsp;/is', '', $string);

    preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $t_string);
    if(count($t_string[0]) - 0 > $sublen) $string = join('', array_slice($t_string[0], 0, $sublen));
    else $string = join('', array_slice($t_string[0], 0, $sublen));

    return $string;
}



function toarabia($str){
    $num=0;
    $bins=array("零","一","二","三","四","五","六","七","八","九",'a'=>"个",'b'=>"十",'c'=>"百",'d'=>"千",'e'=>"万");
    $bits=array('a'=>1,'b'=>10,'c'=>100,'d'=>1000,'e'=>10000);
    foreach($bins as $key=>$val){
        if(strpos(" ".$str,$val)) $str=str_replace($val,$key,$str);
    }
    foreach(str_split($str,2) as $val){
        $temp=str_split($val,1);
        if(count($temp)==1) $temp[1]="a";
        if(isset($bits[$temp[0]])){
            $num=$bits[$temp[0]]+(int)$temp[1];
        }else{
            $num+=(int)$temp[0]*$bits[$temp[1]];
        }
    }
    return $num;
}



    
    //验证码
    function check_verify($code,$id=''){ 
    $verify = new \Think\Verify();  
    return $verify->check($code,$id);
    }
    //见点奖

	